import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  ManyToOne,
  JoinColumn,
  OneToMany,
} from "typeorm";
import { ManualTimestamp } from "../decorators/manual-timestamp.decorator";
import { MapAreaEntity } from "./map-area.entity";
import { NpcDetailEntity } from "./npc-detail.entity";

/**
 * NPC集群表
 * 存储NPC集群的基础信息（如"强盗群"、"士兵群"等）
 */
@Entity("npc_clusters")
@ManualTimestamp()
export class NpcClusterEntity {
  @PrimaryGeneratedColumn({ comment: "NPC集群ID" })
  id!: number;

  @Column("varchar", { length: 100, comment: "集群名称" })
  name!: string;

  @Column("int", { name: "area_id", comment: "所属区域ID" })
  areaId!: number;

  @Column("int", { name: "type_id", comment: "集群类型ID (1:怪物群, 2:NPC)" })
  typeId!: number;

  @Column("int", { name: "attack_power", comment: "攻击力", default: 0 })
  attackPower!: number;

  @Column("tinyint", {
    name: "is_active",
    comment: "是否激活 (1:激活, 0:禁用)",
    default: 1,
  })
  isActive!: number;

  @Column("datetime", { name: "created_at", comment: "创建时间" })
  created_at!: Date;

  @Column("datetime", {
    name: "updated_at",
    comment: "更新时间",
    nullable: true,
  })
  updated_at!: Date | null;

  // 关联关系
  @ManyToOne(() => MapAreaEntity, { nullable: true })
  @JoinColumn({ name: "area_id" })
  area!: MapAreaEntity;

  @OneToMany(() => NpcDetailEntity, (detail) => detail.cluster)
  details!: NpcDetailEntity[];
}
